﻿<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Layouts/List.Master" CodeBehind="DeliveredStatistics.aspx.cs" Inherits="HHMMS.UI.Modules.Report.DeliveredStatistics" %>


<asp:Content ContentPlaceHolderID="head" ID="idFormTitle" runat="server">
    <!-- title -->    
<title>出库分析报表</title>
<web:Script ID="Script1" runat="server" src="~/Scripts/highcharts.js" />
<web:Script ID="Script2" runat="server" src="~/Scripts/Common.js" />
<%--<web:Script ID="Script3" src="~/Scripts/lhgdialog/lhgdialog.js" runat="server" />--%>
</asp:Content>

<asp:Content ID="idContent" ContentPlaceHolderID="Content" runat="Server">   
    <!-- 搜索框 -->
	<div class="search" id="search" style="margin-top:2px;">
        <web:search ID="GridSearch" GridViewId="SmartGridView1" runat="server">            
            <SearchConditionTemplate>                                       
                <table cellpadding="0" cellspacing="0" width="95%">
			        <tr>
                        <th>
                            开始日期：
                        </th>
                        <td>
                            <web:DatePicker ID="dpCreateDtStart" Name="beginTime" runat="server" DateTimeFormat="yyyy-MM-dd"
                                validator="required"></web:DatePicker>
                        </td>
                        <th>
                            结束日期：
                        </th>
                        <td>
                            <web:DatePicker ID="dpCreateDtEnd" Name="endTime" runat="server" DateTimeFormat="yyyy-MM-dd"
                                validator="required"></web:DatePicker>
                        </td> 
                        <th>
                            物资编号：
                        </th>
                        <td>
                            <asp:TextBox ID="txtMaterialsNo" name="MaterialsNo" CssClass="txtSelect" runat="server"></asp:TextBox>
                        </td>                                     
                    </tr>
                    <tr>
                        <th>
                            物资名称：
                        </th>
                        <td>
                            <asp:TextBox ID="txtMaterialsName" name="MaterialsName" CssClass="txtSelect" runat="server"></asp:TextBox>
                        </td>
                        <th>
                            物资规格（型号）：
                        </th>
                        <td>
                            <asp:TextBox ID="txtMaterialsModel" name="MaterialsModel" CssClass="txtSelect" runat="server"></asp:TextBox>
                        </td>
                        <th>
                            领料人：
                        </th>
                        <td>
                            <asp:TextBox ID="txtPickingor" name="Pickingor" CssClass="txtSelect" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            班组：
                        </th>
                        <td>
                            <asp:TextBox ID="txtTeam" Name="Team" CssClass="txtSelect" runat="server"></asp:TextBox>
                        </td>
                        <th>
                            机车号：
                        </th>
                        <td>
                            <asp:TextBox ID="txtLocomotiveNo" Name="LocomotiveNo" CssClass="txtSelect" runat="server"></asp:TextBox>
                        </td>
                        <th>
                            机车修程：
                        </th>
                        <td>
                            <asp:TextBox ID="txtRepairProcess" Name="RepairProcess" CssClass="txtSelect" runat="server"></asp:TextBox>
                            <asp:TextBox ID="txtType" Visible="false" Name="Type" CssClass="txtSelect" runat="server"></asp:TextBox>
                        </td>
                    </tr>

                    <tr>
                        <th>
                            出库数量：
                        </th>
                        <td>
                            <asp:TextBox ID="txtDeliveredNum" Name="DeliveredNum" CssClass="txtSelect" runat="server"></asp:TextBox>
                        </td>
                        <th>
                            计量单位：
                        </th>
                        <td>
                            <asp:TextBox ID="txtUnit" Name="Unit" CssClass="txtSelect" runat="server"></asp:TextBox>
                        </td>
                        <th>
                            单价：
                        </th>
                        <td>
                            <asp:TextBox ID="txtPrice" Name="Price" CssClass="txtSelect" runat="server"></asp:TextBox>
                        </td>
                    </tr>

                     <tr>
                        <th>
                            总金额：
                        </th>
                        <td>
                            <asp:TextBox ID="txtAmount" Name="Amount" CssClass="txtSelect" runat="server"></asp:TextBox>
                        </td>
                        <th>
                            发料人：
                        </th>
                        <td>
                            <asp:TextBox ID="txtSender" Name="Sender" CssClass="txtSelect" runat="server"></asp:TextBox>
                        </td>
                        <th>
                            是否交旧：
                        </th>
                        <td>
                        <web:SmartDropDownList ID="dropIsOld" Name="IsOld" runat="server"  DictionaryCode="YesOrNo" CssClass="txtSelect" />
                           <%-- <asp:TextBox ID="txtIsOld" Name="IsOld" CssClass="txtSelect" runat="server"></asp:TextBox>--%>
                        </td>
                    </tr>
                </table>
            </SearchConditionTemplate>                      
        </web:search>        
    </div>

    <div class="datalist">
	    <!-- 工具栏 -->
	    <div class="toolbar"  style="height:30px;">
         <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButtonExport_Click">
                <span>
                    <img id="Img2" alt="" runat="server" src="~/Images/icon_excel.gif" style="border: 0px" />导出
                </span>
            </asp:LinkButton>
	    </div>
	    <div class="datagrid"  style="clear:left;">    

            <!--------------------------- List Area --------------------------->
            <web:SmartGridView ID="SmartGridView1" runat="server" AutoGenerateColumns="False"
                Width="100%" DataKeyNames="Id" DataSourceID="SmartDataSource1" PageSize="10">
                <Columns>  
                    <asp:BoundField DataField="SubmitDt" HeaderText="出库时间" SortExpression="SubmitDt" ItemStyle-HorizontalAlign="left" />
                    <asp:BoundField DataField="MaterialsNo" HeaderText="物资编号" SortExpression="MaterialsNo" ItemStyle-HorizontalAlign="left" />
                    <asp:BoundField DataField="MaterialsName" HeaderText="物资名称"  ItemStyle-HorizontalAlign="center" SortExpression="MaterialsName"/>
                    <asp:BoundField DataField="MaterialsModel" HeaderText="物资规格（型号）" ItemStyle-HorizontalAlign="center" SortExpression="MaterialsModel"/>
                    <asp:BoundField DataField="DeliveredNum" HeaderText="出库数量" ItemStyle-HorizontalAlign="left" SortExpression="DeliveredNum" />
                    <asp:BoundField DataField="Unit" HeaderText="计量单位" ItemStyle-HorizontalAlign="left" SortExpression="Unit"/>
                    <asp:BoundField DataField="Price" HeaderText="单价" ItemStyle-HorizontalAlign="left" SortExpression="Price"/>
                    <asp:BoundField DataField="Amount" HeaderText="总金额" ItemStyle-HorizontalAlign="left" SortExpression="Amount" />
                    <asp:BoundField DataField="Pickingor" HeaderText="领料人" ItemStyle-HorizontalAlign="left"  SortExpression="Pickingor"/>
                    <asp:BoundField DataField="Team" HeaderText="班组" ItemStyle-HorizontalAlign="left" SortExpression="Team"/>
                    <asp:BoundField DataField="LocomotiveNo" HeaderText="机车号" ItemStyle-HorizontalAlign="left" SortExpression="LocomotiveNo" />
                    <asp:BoundField DataField="RepairProcess" HeaderText="机车修程" ItemStyle-HorizontalAlign="left" SortExpression="RepairProcess" />
                    <asp:BoundField DataField="Sender" HeaderText="发料人" ItemStyle-HorizontalAlign="left" SortExpression="Sender" />
                     <web:DataDictonaryBoundField HeaderStyle-Width="100px" DataField="IsOld" DictionaryCode="YesOrNo"
                    HeaderText="是否交旧" SortExpression="IsOld" />
                     <asp:TemplateField HeaderText="查看">
                        <ItemStyle HorizontalAlign="Center" />
                        <HeaderStyle Wrap="False" HorizontalAlign="Center" />
                        <ItemTemplate>
                            <table width="46px">
                                <tr>
                                   <td style="border: 0px solid #fff;">
                                        <asp:ImageButton ID="ibtnEdit" runat="server" ToolTip="机车图形报表" _KeyId='<%#Eval("LocomotiveNo")%>'
                                            ImageUrl="~/images/com/rtm_tb_srh.gif" CausesValidation="False" OnClientClick="return openEditor(this);" >
                                        </asp:ImageButton>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <PagerSettings />
                <EditRowStyle HorizontalAlign="Center" />
            </web:SmartGridView>
    
            <web:SmartSqlDataSource ID="SmartDataSource1" runat="server" SelectCommand="DeliveredStatistics.list" SelectCountCommand="DeliveredStatistics.list.count"
            SelectCommandAutoPageWrap="true" DefaultSortExpression="ID desc">       
                        
            </web:SmartSqlDataSource>
        </div>
	</div>
    <div id="DeliveredStateChart" >
    
    </div>
    <p style="text-align:center"><a href="#search" style=" text-decoration:none">回到顶部</a></p>
    <script language="javascript" type="text/javascript">
    //加载最近6个月的的总额加载到条形图
        function openEditor(_this) { 
            var locomotiveNo = _this.attributes["_KeyId"].value;
            
            if (locomotiveNo == "" || locomotiveNo == null) {
                alert("机车号为空不能查询！");
                return;
            }
            $.dataservice("MaterialsProvider$GetChart", { locomotiveNo: locomotiveNo }, function (data) {

                var result = data,
                    categories = [],
                    data = [],
                    chart,
                    colors = ['#4572A7', '#AA4643', '#89A54E', '#80699B', '#3D96AE']; //条的颜色

                //未返回结果则退出
                if (!result || result.length <= 0)
                    return false;

                //初始化绑定数据
                $.each(result, function (index, item) {
                    categories.push(item.SubmitDt);
                    item.y = item.Amount;
                    if (index < result.length - 1)
                        item.color = colors[0];
                    else
                        item.color = colors[1];
                    data.push(item);
                });

                try {
                    //初始化图表
                    chart = new Highcharts.Chart({
                        chart: {
                            renderTo: 'DeliveredStateChart',
                            type: 'column',
                            width: 500,
                            height: 260,
                            align: 'center',
                            style: {
                                margin: 'auto'
                            }
                        },
                        credits: {
                            enabled: false
                        },
                        title: {
                            text: locomotiveNo + '机车图形报表',
                            style: {
                                fontSize: '14px',
                                fontFamily: '微软雅黑'
                            }
                        },
                        xAxis: {
                            categories: categories,
                            //x轴刻度文本
                            labels: {
                                formatter: function () {
                                    return this.value
                                },
                                style: {
                                    fontSize: '11px',
                                    fontWeight: 'normal',
                                    paddingTop: '3px',
                                    fontFamily: '宋体',
                                    color: '#000'
                                }
                            }
                        },
                        yAxis: {
                            min: 0,
                            title: {
                                text: '总金额'
                            }
                        },
                        legend: {
                            enabled: false
                        },
                        plotOptions: {
                            column: {
                                cursor: 'pointer',
                                dataLabels: {
                                    enabled: true,
                                    color: colors[0],
                                    //每个条形上面显示的信息格式化
                                    formatter: function () {
                                        return this.y;
                                    }
                                },
                                pointWidth: 45
                            }
                        },
                        tooltip: {
                            //鼠标经过提示信息格式化
                            formatter: function () {
                                var point = this.point;
                                return "日期：" + this.x
                        + "<br />总金额：" + this.y;
                            }
                        },
                        series: [{
                            name: 'DeliveredStateChart',
                            data: data
                        }]
                    });
                }
                catch (e) { 
                
                }
                //展现
                //location.hash = "DeliveredStateChart";
                $('html,body').animate({ scrollTop: $("#DeliveredStateChart").offset().top }, 500);

            });
            return false;
        }
    </script>
</asp:Content>